<?php

namespace App\Admin\Controllers;

use App\Admin\Controllers\Helpers\LinkHelper;
use App\Constant\CommissionEnum;
use App\Models\Commission;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GroupcashController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Commission(), function (Grid $grid) {
            $grid->quickSearch('id', 'user_id','user.uuid','user.nickname')->placeholder('输入 id\uuid\用户昵称\uid')->auto(false);;

            $grid->model()->with(['user'])->whereIn('source',['group_invite','group_cash']);
            $grid->model()->orderBy('created_at', 'desc');

            $grid->column('id')->sortable();
            $grid->column('user_id', '用户Uuid')->display(function () {
                return LinkHelper::displayUser($this->user);
            });
            $grid->column('child_user_id', '下级用户Uuid')->display(function () {
                return LinkHelper::displayUser($this->child);
            });
            // $grid->column('child_user_withdraw_id');
            $grid->column('child_user_money');
            $grid->column('user_money');
            $grid->column('exchange_rate');
            $grid->column('amount');
            $grid->column('source')
                ->using(CommissionEnum::getSourceExplains())
                ->label(CommissionEnum::getSourceColors());
            $grid->column('remark');
            $grid->column('child_user_withdraw_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user_id');
                $filter->equal('child_user_id');
            });

            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableBatchActions();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Commission(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('child_user_id');
            $show->field('child_user_withdraw_id');
            $show->field('child_user_money');
            $show->field('user_money');
            $show->field('exchange_rate');
            $show->field('amount');
            $show->field('child_user_withdraw_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }
}
